/* eslint no-unused-vars:0 */
import React, { Component } from 'react';
import {
    Form,
    Icon,
    Input,
    Button,
    Row,
    Col,
    Select,
    Menu,
    Table,
    LocaleProvider,
    DatePicker,
    message,
    Modal,
    Tooltip,
    Cascader,
    Checkbox,
    AutoComplete
} from 'antd';
import './index.less';
// 由于 antd 组件的默认文案是英文，所以需要修改为中文
import zhCN from 'antd/lib/locale-provider/zh_CN';
import moment from 'moment';
import 'moment/locale/zh-cn';
import 'antd/dist/antd.css';

const Option = Select.Option;

const FormItem = Form.Item;
//form代码，没有什么改进，把下面的提交按钮去掉就行
class AddSolutionForm extends Component {
    constructor(props) {
        super(props);
        this.state = {
            referenceLevels: []
        };
    }

    findAllReferenceLevels() {
        this.$get('/riskSolution/findAllReferenceLevels')
            .then((res) => {
                this.setState({
                    referenceLevels: res.allReferenceLevels
                });
            })
            .catch((e) => {
                console.log(e);
            });
    }

    componentWillMount() {
        this.findAllReferenceLevels();
    }

    render() {
        const { getFieldDecorator } = this.props.form;

        const formItemLayout = {
            labelCol: {
                xs: {
                    span: 100
                },
                sm: {
                    span: 100
                }
            },
            wrapperCol: {
                xs: {
                    span: 100
                },
                sm: {
                    span: 100
                }
            }
        };

        return (
            <Form {...formItemLayout}>
                <Form.Item label="风险事件ID" layout="inline">
                    {getFieldDecorator('riskId', {
                        rules: [
                            {
                                required: true,
                                message: '请输入风险事件ID'
                            }
                        ]
                    })(<Input />)}
                </Form.Item>
                <Form.Item label="解决方案" layout="inline">
                    {getFieldDecorator('content', {
                        rules: [
                            {
                                required: true
                            }
                        ]
                    })(<Input />)}
                </Form.Item>
                <Form.Item label="参考水平">
                    {getFieldDecorator('referenceLevel', {
                        rules: [
                            {
                                required: true,
                                message: '请选择参考水平'
                            }
                        ]
                    })(
                        <Select
                            className="sub-row2-select"
                            placeholder="请选择"
                            labelInValue
                            style={{
                                width: 200,
                                height: 30
                            }}>
                            {this.state.referenceLevels.map((item) => {
                                return (
                                    <Option key={item.id} value={item.level}>
                                        {item.level}
                                    </Option>
                                );
                            })}
                        </Select>
                    )}
                </Form.Item>

                <Form.Item label="外部链接">
                    {getFieldDecorator('url', {
                        rules: [
                            {
                                required: false
                            }
                        ]
                    })(<Input />)}
                </Form.Item>

                <Form.Item label="打标签(用于识别同类事件)">
                    {getFieldDecorator('tipFlag', {
                        rules: [
                            {
                                required: false
                            }
                        ]
                    })(<Input />)}
                </Form.Item>
            </Form>
        );
    }
}

const WrappedAddSolutionForm = Form.create()(AddSolutionForm);

export default WrappedAddSolutionForm;
